﻿using System;
using System.Collections.Generic;

namespace DbManager.DataRequest
{
    public class DataRequestClient:IDataRequest
    {
        private string _surname = string.Empty;
        private string _name = string.Empty;
        private string _fatherName = string.Empty;
        private string _telG = string.Empty;
        private string _telM = string.Empty;
        private string _adress = string.Empty;
        private bool _blackList = true;

        public void SetRequestParameters(Dictionary<string, string> parametersDictionary)
        {
            if (parametersDictionary.ContainsKey("surname") &&
                parametersDictionary.ContainsKey("name") &&
                parametersDictionary.ContainsKey("fatherName") &&
                parametersDictionary.ContainsKey("telG") &&
                parametersDictionary.ContainsKey("telM") &&
                parametersDictionary.ContainsKey("adress") &&
                parametersDictionary.ContainsKey("blackList"))
            {
                _surname = parametersDictionary["surname"];
                _name = parametersDictionary["name"];
                _fatherName = parametersDictionary["fatherName"];
                _telG = parametersDictionary["telG"];
                _telM = parametersDictionary["telM"];
                _adress = parametersDictionary["adress"];
                _blackList = bool.Parse(parametersDictionary["blackList"]);
            }
        }

        public string GetSelectQuery()
        {
            return "SELECT [Идентификатор], [Фамилия], [Имя], [Отчество], [Телефон гор], [Телефон моб], [Адрес], [Черный список] FROM [Клиент] ORDER BY [Идентификатор]";
        }

        public string GetSelectQueryById()
        {
            throw new NotImplementedException();
        }

        public string GetInsertQuery()
        {
            if (string.IsNullOrEmpty(_surname) ||
                string.IsNullOrEmpty(_name) ||
                string.IsNullOrEmpty(_fatherName) ||
                string.IsNullOrEmpty(_telG) ||
                string.IsNullOrEmpty(_telM) ||
                string.IsNullOrEmpty(_adress))
            {
                return string.Empty;
            }
            return "INSERT INTO [Клиент] ([Фамилия], [Имя], [Отчество], [Телефон гор], [Телефон моб], [Адрес], [Черный список]) VALUES ('" + _surname + "', '" + _name + "', '" + _fatherName + "', '" + _telG + "', '" + _telM + "', '" + _adress + "', " + _blackList + ")";
        }

        public string GetUpdateQuery(int id)
        {
            if (string.IsNullOrEmpty(_surname) ||
                string.IsNullOrEmpty(_name) ||
                string.IsNullOrEmpty(_fatherName) ||
                string.IsNullOrEmpty(_telG) ||
                string.IsNullOrEmpty(_telM) ||
                string.IsNullOrEmpty(_adress) || id ==0)
            {
                return string.Empty;
            }

            return "UPDATE [Клиент] SET [Фамилия]='" + _surname + "', [Имя]='" + _name + "', [Отчество]='" + _fatherName + "', [Телефон гор]='" + _telG + "', [Телефон моб]='" + _telM + "', [Адрес]='" + _adress + "', [Черный список]=" + _blackList + " WHERE [Идентификатор]=" + id;
        }

        public string GetDeleteQuery(int id)
        {
            if (id == 0)
            {
                return string.Empty;
            }
            return "DELETE FROM [Клиент] WHERE [Идентификатор]=" + id;
        }
    }
}
